home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / 8087.arc / TEN.ASM < prev    next >
Encoding:
Assembly Source File  |  1985-02-13  |  1.5 KB  |  49 lines

  1.     PAGE    ,132
  2.     TITLE    Calculate 10**ST
  3. IF1
  4. INCLUDE 87MAC.LIB
  5. ENDIF
  6. CODE    SEGMENT PUBLIC
  7.     ASSUME    CS:CODE,DS:CODE
  8.     PUBLIC    TEN_TO_X
  9. OLD_CW    DW    ?
  10. NEW_CW    DW    ?
  11. ;-----------------------------------------------;
  12. ; This routine will take the top element of    ;
  13. ;  the 8087 stack, and raise ten to that power    ;
  14. ; Input -- ST0 is X                ;
  15. ; Output -- ST0 is 10**X            ;
  16. ; This routine uses two stack positions plus    ;
  17. ;   the parameter, a total of three.        ;
  18. ;------------------------------------------------
  19. TEN_TO_X    PROC    NEAR
  20.                 ;-----ST0-------;-----ST1-------;---ST2-------
  21.                 ;     X     ;      ?    ;    ?
  22.     FLDL2T            ; LOG2(10)    ;      X    ;    ?
  23.     FMULP    ST1,ST0     ;X LOG2(10) = E ;      ?    ;    ?
  24.     FNSTCW    OLD_CW        ;---------------;---------------;-------------
  25.     FWAIT            ; Get the current status word
  26.     MOV    AX,OLD_CW    ; Save it
  27.     AND    AX, NOT 0C00H    ; Set rounding control to
  28.     OR    AX, 0400H    ;  round towards -infinity
  29.     MOV    NEW_CW,AX
  30.     FLDCW    NEW_CW        ;---------------;---------------;-------------
  31.     FLD1            ;    1    ;    E    ;    ?
  32.     FCHS            ;      -1    ;    E    ;    ?
  33.     FLD    ST1        ;    E    ;      -1    ;    E
  34.     FRNDINT         ; INT(E) = I    ;      -1    ;    E
  35.     FLDCW    OLD_CW        ;        ;        ;
  36.     FXCH    ST2        ;    E    ;      -1    ;    I
  37.     FSUB    ST0,ST2     ; E - I = F    ;      -1    ;    I
  38.     FSCALE            ; F*2**-1 = F/2 ;      -1    ;    I
  39.     F2XM1            ;(2**F/2)-1    ;      -1    ;    I
  40.     FSUBRP    ST1,ST0     ; 2**F/2    ;    I    ;    ?
  41.     FMUL    ST0        ; 2**F        ;    I    ;    ?
  42.     FSCALE            ;(2**F)*(2**I)    ;    I    ;    ?
  43.     FXCH    ST1        ;    I    ;     2**(I+F)    ;    ?
  44.     FISTP    OLD_CW        ;   2**(I+F)    ;    ?    ;    ?
  45.     RET            ;  10**X    ;    ?    ;    ?
  46. TEN_TO_X    ENDP
  47. CODE    ENDS
  48.     END
  49.